import { defineConfig } from 'vite'
import Vue from '@vitejs/plugin-vue'
// https://github.com/hannoeru/vite-plugin-pages
import Pages from 'vite-plugin-pages'
import Legacy from '@vitejs/plugin-legacy'
import Components from 'unplugin-vue-components/vite'
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
const path = require('path')

// https://vitejs.dev/config/
export default defineConfig({
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src')
    }
  },
  plugins: [
    Vue(),
    Legacy({
      targets: ['defaults', 'not IE 11'],
      modernPolyfills: true
    }),
    Components({
      dirs: ['src/components'],
      resolvers: [
        AntDesignVueResolver({
          importStyle: 'less'
        })
      ]
    }),
    Pages({
      pagesDir: [
        { dir: 'src/pages/Normal', baseRoute: '' },
        { dir: 'src/pages/Management', baseRoute: '' },
        { dir: 'src/pages/Client', baseRoute: '' }
      ],
      extensions: ['vue'],
      exclude: ['**/components/*.*']
    })
  ],
  css: {
    preprocessorOptions: {
      less: {
        modifyVars: {
          hack: `true; @import (reference) "${path.resolve('src/assets/style/variables.less')}";`
        },
        javascriptEnabled: true
      }
    }
  },
  server: {
    port: 9001
  },
  build: {
    target: 'es2015'
  }
})
